/**
 * @author Robert_Csala
 */

mindgraph = {};

// Simple logging to the console, if it is accessible
mindgraph.log = function (message) {
	if (message) {
		if ((window && window.console) || console) {
			var cns = (console) ? console : window.console;
			cns.log(message);
		}
		else {
			alert(message);
		}
	}
}

// Gets the name of the participant from the id
mindgraph.getParticipantName = function () {
	var id = wave.getViewer().getId();
	var ndx = id.indexOf('@');
	if(ndx > 0) {
		return id.substring(0, ndx);
	}
	return id;
}

// id generator
mindgraph.idCount = 0;

// updates the id count based on the numeric part of the idString
mindgraph.updateIdCount = function (idString) {
	var testExp = /^[A-Za-z]+([0-9]+)$/;
	if(idString && testExp.test(idString)) {
		var split = testExp.exec(idString);
		if(split && split[1]) {
			var calcId = Number(split[1]);
			if (mindgraph.idCount < calcId) {
				mindgraph.idCount = calcId;
			}
		}
	} 
}

// generates a new element id based on the participant name and the idCount
mindgraph.generateElementId = function () {
	var id = mindgraph.getParticipantName();
	id += mindgraph.idCount;
	mindgraph.idCount += 1;
	return id;
}
